package com.powermgr.boringtest.task.impl;

import com.powermgr.boringtest.bean.PrData;
import com.powermgr.boringtest.task.PrTask;
import com.powermgr.boringtest.utils.CmdUtils;
import com.powermgr.boringtest.utils.ConfigUtils;
import com.powermgr.boringtest.utils.EmailUtils;
import com.powermgr.boringtest.utils.RootUtils;
import lombok.extern.log4j.Log4j2;

import java.io.File;

import static com.powermgr.boringtest.utils.ConfigUtils.ROOT_FALSE;


/**
 * FlashDeviceTask
 *
 * @author qiuxiangdong
 * @date 2023/9/23 10:26
 */
@Log4j2
public class FlashDevicePrTask implements PrTask<PrData> {
    @Override
    public boolean execute(PrData prData) {
        prData.setState("1");
        log.info("开始执行刷机：sn = " + prData.getDevice().getSn() + ", ld = " + prData.getDevice().getLd());
        boolean goRoot =  RootUtils.goRoot(
                ConfigUtils.SN + File.separator + prData.getDevice().getSn() +  File.separator + "pr" + File.separator + "version",
                ConfigUtils.PR_TOOLS + File.separator  + "rk3568.exe",
                prData.getDevice().getSn(),
                prData.getDevice().getLd());
        if (!goRoot) {
            EmailUtils.SendEmail(prData, ROOT_FALSE);
            return false;
        }
        return true;
    }
}